/**
 * This file is responsible for performing actions on the displayed page:
 * <ul>
 * 	<li> marking and unmarking pages </li>
 * 	<li> creating content dynamically by loading </li>
 * </ul>
 */

//Marking code
/**
 * sets all the checkboxes with name "mark" to same checked state 
 * @param val: true or false, true to check false to uncheck
 */
function SetAllCheckboxes(val){
  field = document.crsForm.mark;
  for (i = 0; i < field.length; i++){
      field[i].checked = val;
  }

}
$("#markAll").click(function(){SetAllCheckboxes(true)});
$("#UnMarkAll").click(function(){SetAllCheckboxes(false)});


//reloading menu
$(document).ready(function(){
  $(".menuLink").click(function(){
    $("#title").html($(this).attr("title"));
    $("#contenttext").load('contents/' + $(this).attr("id") + '.jsp');  
  });
});

$(".handleMarked").click(function(){
	//first do the action
	params =  "module=courses&action="+ $(this).attr("id")+"&"+ $("#crsForm").serialize();
	$.post("handleMarked", params,function(data){
		//making it work with FF......
		var serializer = new XMLSerializer();
		var xml = serializer.serializeToString(data);
		data = xml.replace("<firefoxsucks>","").replace("</firefoxsucks>","");
		//real begining fo function
		if(data != "success"){
			//reload content
		    alert("Operation failed!");  
		}
		$("#contenttext").load('contents/courses.jsp');
	});
});
